define([
    "jquery",
    "IO",
    "bootbox",
    "bootstrap"
],function($,IO,bootbox,bootstrap){
    $(function () {

        getTable();
        function getTable(){
            var grid;
            //每列数据列性
            var columns = [
                {
                    title: '小组编号',
                    dataIndex: 'team_id',
                    dataSource: function (data, datarow, gridobj, current_column) {
                        return "<span>"+ data[datarow].team_id+"</span>";
                    }
                },
                {
                    title: '培训编号',
                    dataIndex: 'train_id',
                    dataSource: function (data, datarow, gridobj, current_column) {
                        return "<span>"+ data[datarow].train_id+"</span>";
                    }
                },
                {
                    title: '行动学习',
                    dataIndex: 'section_type',
                    dataSource: function (data, datarow, gridobj, current_column) {
                        if(data[datarow].section_type == 0){
                            return "问题驱动";
                        }
                        if(data[datarow].section_type == 1){
                            return "原理反思";
                        }
                        if(data[datarow].section_type == 2){
                            return "行动目标";
                        }
                        if(data[datarow].section_type == 3){
                            return "行动反馈";
                        }
                        if(data[datarow].section_type == 4){
                            return "行动推进";
                        }
                    }
                },
                {
                    title: '讨论内容',
                    dataIndex: 'content',
                    dataSource: function (data, datarow, gridobj, current_column) {
                        var back_data = data[datarow].content;
                        var comment_body;
                        if(data[datarow].content.length>10){
                            comment_body = back_data.substring(0,10) + "......";

                        }else{
                            comment_body = data[datarow].content;
                        }
                        return "<span>"+comment_body +"</span>";
                    }
                },
                {
                    title: '讨论创建时间',
                    dataIndex: 'gender',
                    dataSource: function (data, datarow, gridobj, current_column) {
                        var date = new Date(data[datarow].timestamp);
                        create_year = date.getFullYear();
                        create_month = (date.getMonth()+1 < 10 ? '0'+(date.getMonth()+1) : date.getMonth()+1);
                        create_day = date.getDate() < 10 ? '0'+date.getDate() : date.getDate() ;
                        create_hours = date.getHours() < 10 ? '0' + date.getHours() : date.getHours() ;
                        create_min = date.getMinutes() < 10 ? '0' + date.getMinutes() : date.getMinutes() ;
                        create_sec = date.getSeconds() < 10 ? '0' + date.getSeconds() : date.getSeconds();
                        return "<span>"+create_year+'-'+create_month+'-'+create_day+' '+create_hours+':'+create_min+':'+create_sec+ ' '+"</span>";
                    }
                },

            ];


            //数组初始化
            function dataInit() {
                grid = new Grid("/ct/act/panelDiscussion_list", $("#table_my_toast"), $("#paging_my_toast"), 1, 10, columns, get_input_param(), 10);

                //初始化
                grid.Init();
            }

            //获取输入框内容
            function get_input_param() {
                var team_id = $("#team_id").val();
                var train_id = $("#train_id").val();
                var section_type = $("#section_type").val();
                var keyword = $("#keyword").val();
                var params = "team_id=" + team_id + "&train_id=" + train_id + "&section_type=" + section_type + "&keyword=" + keyword;

                return params;
            }
            dataInit();

            //点击搜索查询
            $("#search").bind("click", function () {
                dataInit();
            });

        }
        $("#export_btn").on('click',function(){
            var team_id = $("#team_id").val();
            var train_id = $("#train_id").val();
            var section_type = $("#section_type").val();
            var url = "http://zjprod.snsunion.cn:8081/CorporateTraining/api/v1/"
            if(train_id == "-1" && section_type == "-1" && team_id == "-1"){
                window.location.href = ""+url+"teamtalks/export";
            }
            //train_id
            if(train_id != "-1" && section_type == "-1" && team_id == "-1"){
                window.location.href = ""+url+"teamtalks/export?train_id="+train_id+"";
            }
            //section_type
            if(train_id == "-1" && section_type != "-1" && team_id == "-1"){
                window.location.href = ""+url+"teamtalks/export?section_type="+section_type+"";
            }
            //team_id
            if(train_id == "-1" && section_type == "-1" && team_id != "-1"){
                window.location.href = ""+url+"teamtalks/export?team_id="+team_id+"";
            }
            //train_id&&section_type
            if(train_id != "-1" && section_type != "-1" && team_id == "-1"){
                window.location.href = ""+url+"teamtalks/export?team_id="+team_id+"";
            }
            //train_id&&team_id
            if(train_id != "-1" && section_type == "-1" && team_id != "-1"){
                window.location.href = ""+url+"teamtalks/export?team_id="+team_id+"";
            }
            //section_type&&team_id
            if(train_id == "-1" && section_type != "-1" && team_id != "-1"){
                window.location.href = ""+url+"teamtalks/export?team_id="+team_id+"";
            }
            //train_id&&section_type&&team_id
            if(train_id != "-1" && section_type != "-1" && team_id != "-1"){
                window.location.href = ""+url+"teamtalks/export?train_id="+train_id+"&section_type="+section_type+"&team_id="+team_id+"";
            }
        })

    });

})
